package com.joyance.test_servlet.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class TestServletResponse extends HttpServlet {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;


    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // ServletResponse
        System.out.println("ServletResponse================");
        // setCharacterEncoding;
        // resp.setCharacterEncoding("utf-8");
        System.out.println(resp.getCharacterEncoding());
        // getOutputStream
        ServletOutputStream outputStream = resp.getOutputStream();
        // outputStream.print(4L);
        // getWriter
        // PrintWriter printWriter = resp.getWriter();
        // printWriter.println("hello");
        // setContentType
        resp.setContentType("text/xml");
        resp.setHeader("Content-disposition", "attachment; filename=abc.xml");
        // setContentLength
        resp.setContentLength(82);
        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><person><id>1</id><name>guanyue</name>";
        outputStream.write(xml.getBytes());
    }


}
